﻿<%@ WebHandler Language="C#" Class="login" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using System.Web.Services;

public class login : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    private StringBuilder sb = null;
    public DataSet ds = null;
    public DataTable dt = null;
    private string sqlwhere = "";
    public void ProcessRequest(HttpContext context)
    {
        string type = PageBase.ext_string(context.Request.Params["type"]);
        switch (type)
        {
            case "yzloginid":
                loginid_yz(context);
                break;
            case "post":
                getinfo(context);
                break;
            default:
                break;
        }
    }
    [WebMethod(EnableSession = true)]
    public void loginid_yz(HttpContext context)
    {
        string loginid_yz = PageBase.ext_string(context.Request.Params["loginid_yz"]);

        sqlwhere = loginid_yz.Trim() != "" ? "select id from [sys_users] where loginid = '" + loginid_yz + "'" : "";

        dt =   DBHelper.ExecuteDataTable(sqlwhere);
        sb = new StringBuilder();
        if (dt.Rows.Count > 0)
        {
            sb.Append("{\"state\":\"true\"}");
        }
        else
        {
            sb.Append("{\"state\":\"false\"}");
        }
        context.Response.Write(sb.ToString());
        context.Response.ContentType = "text/json";
        context.Response.End();
    }
    public void getinfo(HttpContext context)
    {
        LoginUser list = new LoginUser();
        using (System.IO.StreamReader sr = new System.IO.StreamReader(context.Request.InputStream))
        {
            string s = sr.ReadToEnd();
            list = new JavaScriptSerializer().Deserialize<LoginUser>(s);
        }
        string LOGINID = list.LOGINID;
        string PASSWORD = list.PASSWORD;
        sqlwhere = LOGINID.Trim() != "" ? "select a.ID,a.loginid,a.phone,a.username,a.password,a.role,rtrim(ltrim(a.islookme)) as islookme from [sys_users] a  where a.loginid = '" + LOGINID + "'" : "";
        sqlwhere += PASSWORD.Trim() != "" ? " and a.password = '" + PASSWORD + "'" : "";
        dt = DBHelper.ExecuteDataTable(sqlwhere);
        sb = new StringBuilder();
        if (dt.Rows.Count > 0)
        {
            sb.Append("{\"state\":\"true\"");
            sb.Append(",\"id\":\"" + dt.Rows[0]["id"] + "\"");
            sb.Append(",\"loginid\":\"" + dt.Rows[0]["loginid"].ToString() + "\"");
            sb.Append(",\"username\":\"" + dt.Rows[0]["username"].ToString() + "\"");
            sb.Append(",\"password\":\"" + dt.Rows[0]["password"].ToString() + "\"");
            sb.Append(",\"islookme\":\"" + dt.Rows[0]["islookme"].ToString() + "\"");
            sb.Append(",\"phone\":\"" + dt.Rows[0]["phone"].ToString() + "\"");
            sb.Append(",\"role\":\"" + dt.Rows[0]["role"].ToString() + "\"}");
            LoginUser user = Utility.CheckLogin(LOGINID, PASSWORD);
        }
        else
        {
            sb.Append("{\"state\":\"false\"}");
        }
        context.Response.Write(sb.ToString());
        context.Response.ContentType = "text/json";
        context.Response.End();
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}